package com.wswy.wzcx.widget.home;

import android.content.Context;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;

@Keep
public class HomeBehavior extends AppBarLayout.Behavior {

  public HomeBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  private RecyclerView currRecyclerView;

  @Override
  public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child,
      View directTargetChild, View target, int nestedScrollAxes, int type) {

    if (target instanceof RecyclerView && type == ViewCompat.TYPE_TOUCH){
      currRecyclerView = (RecyclerView) target;
    }

    return super
        .onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type);
  }



  public void scrollTop(){
    //立即滚动到顶部
    if (currRecyclerView != null){
      currRecyclerView.stopScroll();
      currRecyclerView.scrollToPosition(0);
    }
  }


}
